package com.ch.home.service.serviceImpl.restDishServiceImpl;

import com.ch.home.bean.DishRecipes;
import com.ch.home.mapper.restDishMapper.DishRecipesMapper;
import com.ch.home.service.serviceInterface.restDishService.DishRecipesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.LinkedList;

/**
 * Created by CHEN on 2019/8/28.
 */
@Service
public class DishRecipesServiceImpl implements DishRecipesService {
    @Autowired
    DishRecipesMapper dishRecipesMapper;

    @Override
    public HashMap getPreview(DishRecipes dishRecipes) {
        return null;
    }

    @Override
    public HashMap getAll(DishRecipes dishRecipes) {
        HashMap<Object, Object> result = new HashMap<>( );
        LinkedList<DishRecipes> dishRecipesAndSource = dishRecipesMapper.getDishRecipesAndSource(dishRecipes);
        if (dishRecipesAndSource.size( ) > 0) {
            result.put("message", "success");
        } else {
            result.put("message", "fail");
        }
        result.put("value", dishRecipesAndSource);
        return result;
    }

    @Override
    public HashMap add(DishRecipes dishRecipes) {
        HashMap<Object, Object> result = new HashMap<>( );

        int re = dishRecipesMapper.addDishRecipes(dishRecipes);
        if (re == 1) {
            result.put("message", "success");
        } else {
            result.put("message", "fail");
        }
        return result;
    }

    @Override
    public HashMap update(DishRecipes dishRecipes) {

        HashMap<Object, Object> result = new HashMap<>( );

        int re = dishRecipesMapper.updateDishRecipes( dishRecipes);
        if (re == 1) {
            result.put("message", "success");
        } else {
            result.put("message", "fail");
        }
        return result;
    }
}
